Skip to content

Add auto-barter to trade UI and global toggle to trade agreements#1577

Open
sizzlins wants to merge 8 commits intoDFHack:masterfrom
sizzlins:feature/auto-barter-and-trade-agreement-toggle
Open

Add auto-barter to trade UI and global toggle to trade agreements#1577
sizzlins wants to merge 8 commits intoDFHack:masterfrom
sizzlins:feature/auto-barter-and-trade-agreement-toggle

Conversation

@sizzlins
Copy link
Copy Markdown

  • Adds an 'Auto Barter' feature to the trade window, calculating required values and automatically selecting merchant/fortress goods to match an internal margin factor.
  • Adds a global 'Select Globally' toggle hotkey to the diplomacy requests UI to select/deselect requests from all available tabs.

@sizzlins sizzlins marked this pull request as ready for review April 21, 2026 12:05
@sizzlins
Copy link
Copy Markdown
Author

sizzlins commented Apr 21, 2026

Auto Barter, automatically selects depot goods to match chosen merchants good with a * 1.25 profit margin for the merchant. Expensive means selecting the most valuable item first to trade with. Cheap means choosing the cheapest items first to trade with.
Screenshot 2026-04-21 114046

@sizzlins
Copy link
Copy Markdown
Author

Select Globally, selects all item requests for next years caravan diplomacy.
Screenshot 2026-04-21 102002

@eTzmNcbkrng
Copy link
Copy Markdown

The wiki says you should do this with a macro but doesn't provide an example, I tried searching for one but couldn't find.
This is awesome! I'm going to test it now

FWIW, I tried AI vibe-coding an edit to tradeagreement.lua to give the option to "select by weight". I was trying to get the lightest and heaviest boulders available. I was ultimately unsuccessful but maybe that's something you'd find useful.

@sizzlins
Copy link
Copy Markdown
Author

The wiki says you should do this with a macro but doesn't provide an example, I tried searching for one but couldn't find. This is awesome! I'm going to test it now

FWIW, I tried AI vibe-coding an edit to tradeagreement.lua to give the option to "select by weight". I was trying to get the lightest and heaviest boulders available. I was ultimately unsuccessful but maybe that's something you'd find useful.

the script has a builtin cheat sheet that tells it exactly where to find lists of things like leather, meat, and gems in the game's data, however, it doesn't have a cheat sheet for finding stones and boulders, because it doesn't know how to look up the list of available stones, the script simply hides the select by value button whenever you click on the stone tab.

i am currently working to add this feature, select by weight

…o trade agreements

- Implements persistent, per-civ trade agreement saving/loading
- Adds 'Select by Weight' and 'Select by Value' sorting for Boulders, Metal, Cheese, Crafts, Mugs, Glass, Silk, and almost all other raw materials.
- Includes numerous defensive nil-checks for safe memory parsing.
@sizzlins
Copy link
Copy Markdown
Author

image

@sizzlins sizzlins force-pushed the feature/auto-barter-and-trade-agreement-toggle branch from 7e740b6 to 1529058 Compare April 23, 2026 07:55
@eTzmNcbkrng
Copy link
Copy Markdown

eTzmNcbkrng commented Apr 28, 2026

Found a cropping issue, if the number of items available for trade is long enough I can't see what the last item is because it's covered by the overlay.
As you can see in this screenshot, you can't see the name of what is probably a rabbit buck at the bottom.
image

Also, it looks like the weights being displayed are actually density and not mass. Your screenshot shows the heaviest item being 21400, this is most likely a platinum nugget which has a density of 21400 kg/m3.
Possible to use the Wiki's formula for converting from density to mass?
Weight (in Γ) = Density (in kg/m3) * Volume (in cm3) / 1,000,000 (cm3/m3)

On some categories the select by value and select by weight options are greyed out, I assume they incalculable or some other reason, however on the Wood section they are active but don't do anything.

Edit: I've just noticed that my overlay shows select by weigh but your screenshots and code show select by weight. Is this because of my resolution and UI scale?
    3440 x 1440, Max Interface % set to 65%

@sizzlins
Copy link
Copy Markdown
Author

Is this because of my resolution and UI scale?

Most likely yes. will be fixed if fixable

@sizzlins sizzlins force-pushed the feature/auto-barter-and-trade-agreement-toggle branch from ee5dccb to c22d531 Compare April 28, 2026 17:24
@sizzlins
Copy link
Copy Markdown
Author

implementing the full density * volume / 1,000,000 mass formula would require looking up each items volume from the item definition, which varies by item type. I've renamed the button and dialog from "Select by weight" to "Select by density" with the kg/m³ unit shown in the list, so it's now accurately labeled.

The overlay height reduced from h=7 to h=5, if you're still seeing overlap, you can also reposition the overlay with gui/overlay if it clips on your setup

Added an emptyresult guard, if the material list resolves to zero entries, you now get a "No density data available for wood" announcement instead of a broken empty dialog

"select by weigh", this was a frame width issue , the button labels should now fit within the allocated space.

@eTzmNcbkrng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants